import '../model/paging_model.dart';
import '../utils/date_utils.dart';
import 'result_model.dart';

///考试:学生成绩:查询:请求
class TestStudentScoreQueryReq extends PagingQueryReq {
  final String examId, schoolId, studentId;
  final int status;

  TestStudentScoreQueryReq({
    required this.examId,
    required this.schoolId,
    required this.studentId,
    required this.status,
    super.index,
    super.size,
  });

  @override
  Map<String, dynamic> toMap() {
    final map = super.toMap();
    map['schoolId'] = schoolId;
    map['studentId'] = studentId;
    map['status'] = status;
    return map;
  }
}

///考试:学生成绩:查询:响应
class TestStudentScoreQueryRes extends PagingQueryRes<TestStudentScoreItemRes> {
  TestStudentScoreQueryRes({
    required super.retCode,
    required super.retMessage,
    super.total,
    super.rows,
  });

  factory TestStudentScoreQueryRes.fromModel(final ResultModelRes res) {
    final ret = PagingQueryRes.fromModel(
      res,
      (row) => TestStudentScoreItemRes.fromMap(row),
    );
    return TestStudentScoreQueryRes(
      retCode: ret.retCode,
      retMessage: ret.retMessage,
      total: ret.total,
      rows: ret.rows,
    );
  }
}

///考试:学生成绩:数据项:响应
class TestStudentScoreItemRes {
  final String id, examId, schoolId, studentId;
  final double rawScore, discountScore;
  final int status;
  final DateTime? createdAt;

  const TestStudentScoreItemRes({
    required this.id,
    required this.examId,
    required this.schoolId,
    required this.studentId,
    required this.rawScore,
    required this.discountScore,
    required this.status,
    this.createdAt,
  });

  factory TestStudentScoreItemRes.fromMap(Map<String, dynamic> map) =>
      TestStudentScoreItemRes(
        id: map['id'] ?? '',
        examId: map['examId'] ?? '',
        schoolId: map['schoolId'] ?? '',
        studentId: map['studentId'] ?? '',
        rawScore: map['rawScore'] ?? 0.0,
        discountScore: map['discountScore'] ?? 0.0,
        status: map['status'] ?? 0,
        createdAt: dateUtils.parse('yyyy-MM-dd HH:mm:ss', map['createdAt']),
      );
}

///考试:学生成绩:加载:响应
class TestStudentScoreInfoRes extends TestStudentScoreItemRes with ModelRes {
  @override
  final int retCode;
  @override
  final String retMessage;

  TestStudentScoreInfoRes({
    required this.retCode,
    required this.retMessage,
    required TestStudentScoreItemRes item,
  }) : super(
          id: item.id,
          examId: item.examId,
          schoolId: item.schoolId,
          studentId: item.studentId,
          rawScore: item.rawScore,
          discountScore: item.discountScore,
          status: item.status,
          createdAt: item.createdAt,
        );

  factory TestStudentScoreInfoRes.fromModel(final ResultModelRes res) =>
      TestStudentScoreInfoRes(
        retCode: res.retCode,
        retMessage: res.retMessage,
        item: TestStudentScoreItemRes.fromMap(res.toMap),
      );
}

///考试:学生成绩:新增:请求
class TestStudentScoreAddReq {
  final String examId, schoolId, studentId;
  final double rawScore, discountScore;

  const TestStudentScoreAddReq({
    required this.examId,
    required this.schoolId,
    required this.studentId,
    required this.rawScore,
    required this.discountScore,
  });

  Map<String, dynamic> toMap() => {
        'schoolId': schoolId,
        'studentId': studentId,
        'rawScore': rawScore,
        'discountScore': discountScore,
      };
}

///考试:学生成绩:修改:请求
class TestStudentScoreModifyReq {
  final String id, schoolId, studentId;
  final double rawScore, discountScore;
  final int status;

  const TestStudentScoreModifyReq({
    required this.id,
    required this.schoolId,
    required this.studentId,
    required this.rawScore,
    required this.discountScore,
    required this.status,
  });

  Map<String, dynamic> toMap() => {
        'schoolId': schoolId,
        'studentId': studentId,
        'rawScore': rawScore,
        'discountScore': discountScore,
        'status': status,
      };
}
